//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nccloud.pubimpl.gl.assbalance;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import nc.bd.accperiod.InvalidAccperiodExcetion;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.gl.account.glconst.CurrTypeConst;
import nc.gl.utils.DataFormatUtilGL;
import nc.gl.utils.GLMultiLangUtil;
import nc.itf.gl.accbook.IRemoteBillModel;
import nc.itf.gl.accountingbook.IAccountingbookService;
import nc.itf.gl.pub.IGlPeriod;
import nc.itf.gl.pub.ILinkQueryParamTransfer;
import nc.itf.glcom.para.GLParaAccessor;
import nc.itf.pubbd.profitcenter.IProfitCenterPubService;
import nc.itf.uap.busibean.SysinitAccessor;
import nc.pub.gl.query.AssBlcResultGetter;
import nc.pub.gl.query.CBalanceAssTool;
import nc.pub.gl.query.GlQueryVOAssTool;
import nc.pub.gl.query.GlQueryVOContainer;
import nc.pubitf.accperiod.AccountCalendar;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.ui.fi.uforeport.BSDataSourceControl;
import nc.vo.bd.accassitem.AccAssItemVO;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.account.AccountVO;
import nc.vo.bd.account.pub.AccountGLSimpleVO;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.pub.BDCacheQueryUtil;
import nc.vo.fi.uforeport.IUFOInvokeContext;
import nc.vo.fipub.freevalue.account.proxy.AccAssGL;
import nc.vo.fipub.freevalue.util.FreeValueDefUtil;
import nc.vo.fipub.utils.StrTools;
import nc.vo.gateway60.accountbook.AccountBookUtil;
import nc.vo.gateway60.itfs.AccountByPkThreadCache;
import nc.vo.gateway60.itfs.AccountUtilGL;
import nc.vo.gateway60.itfs.CalendarUtilGL;
import nc.vo.gateway60.itfs.CurrtypeGL;
import nc.vo.gl.balancesubjass.BalanceSubjAssBSVO;
import nc.vo.glcom.ass.AssAccessorManager;
import nc.vo.glcom.ass.AssVO;
import nc.vo.glcom.balance.AttrsValueVO;
import nc.vo.glcom.balance.GLQueryObj;
import nc.vo.glcom.balance.GlQryFormatVO;
import nc.vo.glcom.balance.GlQueryVO;
import nc.vo.glcom.glperiod.GlPeriodVO;
import nc.vo.glcom.tools.BaseCorpChooser;
import nc.vo.glcom.tools.GLPubProxy;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.profitcenter.ProfitcenterVersionVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nccloud.dto.gl.lightgl.displayformattool.ShowContentCenter;
import nccloud.pub.gl.lightgl.ColumnInfo;
import nccloud.pub.gl.lightgl.IColumnInfo;
import nccloud.pubimpl.gl.account.AccountRepUtil;
import nccloud.pubimpl.gl.account.GLReportFormat;
import nccloud.pubimpl.gl.util.JsonUtils;

public class AssBalanceQueryBO {
    private String pk_localcurr;
    private GLReportFormat format = new GLReportFormat(102, 45, 49);

    public AssBalanceQueryBO() {
    }

    public Map<String, Object> queryAssBalance(Map<String, Object> params) throws BusinessException {
        BSDataSourceControl envInit = this.initEnvirment(params);

        Map var17;
        try {
            GlQueryVO qryvo = null;
            if (params.get("link") != null) {
                try {
                    String classname = params.get("class").toString();
                    Class<?> clazz = Class.forName(classname);
                    ILinkQueryParamTransfer transfer = (ILinkQueryParamTransfer)clazz.newInstance();
                    qryvo = (GlQueryVO)transfer.transLinkQueryParam(params);
                } catch (Exception e) {
                    Logger.error(e.getMessage(), e);
                    throw new BusinessException(e.getMessage(), e);
                }
            } else {
                qryvo = this.getQueryVO(params);
                // modify by wy at 2025年6月18日
//                AccountRepUtil.checkQueryVO(qryvo); // 由于发布的自由报表影响，所以去掉校验
                AccountRepUtil.checkPeriodSpan(qryvo);
                this.checkQryObjs(qryvo);
            }

            if (GlQueryVOAssTool.isMultiPages(qryvo)) {
                Logger.info("*************************************************");
                Logger.info("进入辅助余额表单翻页处理，预分为  " + GlQueryVOAssTool.getPages(qryvo) + " 页");
                Logger.info("*************************************************");
                var17 = this.queryMultiPage(qryvo);
                return var17;
            }

            Logger.info("*************************************************");
            Logger.info("进入辅助余额表单页处理");
            Logger.info("*************************************************");
            var17 = this.queryOnePage(qryvo);
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } finally {
            if (envInit != null) {
                envInit.afterPress("", (Object[])null, (IUFOInvokeContext)null);
            }

        }

        return var17;
    }

    public BSDataSourceControl initEnvirment(Map<String, Object> params) throws BusinessException {
        if (params.containsKey("env")) {
            try {
                String env = (String)params.get("env");
                String[] envs = env.replace("[", "").replace("]", "").replaceAll("\"", "").split(",");
                BSDataSourceControl envInit = new BSDataSourceControl();
                envInit.beforePress((String)null, envs, (IUFOInvokeContext)null);
                return envInit;
            } catch (Exception e) {
                Logger.error(e.getMessage());
                throw new BusinessException(e.getMessage(), e);
            }
        } else {
            return null;
        }
    }

    public GlQueryVO constructQueryVO(Map<String, Object> params) throws Exception {
        GlQueryVO qryvo = null;
        if (params.get("link") != null) {
            try {
                String classname = params.get("class").toString();
                Class<?> clazz = Class.forName(classname);
                ILinkQueryParamTransfer transfer = (ILinkQueryParamTransfer)clazz.newInstance();
                qryvo = (GlQueryVO)transfer.transLinkQueryParam(params);
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
                throw new BusinessException(e.getMessage(), e);
            }
        } else {
            qryvo = this.getQueryVO(params);
            AccountRepUtil.checkQueryVO(qryvo);
            AccountRepUtil.checkPeriodSpan(qryvo);
            this.checkQryObjs(qryvo);
        }

        return qryvo;
    }

    public Map<String, Object> queryAssBalance2(Map<String, Object> params) throws BusinessException {
        try {
            GlQueryVO qryvo = this.constructQueryVO(params);
            this.checkQryObjs(qryvo);
            return this.queryPageData(qryvo);
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        }
    }

    public Map<String, Object> queryPageData(GlQueryVO qryvo) throws Exception {
        if (!GlQueryVOAssTool.isMultiPages(qryvo)) {
            Logger.info("*************************************************");
            Logger.info("进入辅助余额表单页处理");
            Logger.info("*************************************************");
            return this.queryOnePage2(qryvo);
        } else {
            Logger.info("*************************************************");
            Logger.info("进入辅助余额表单翻页处理，预分为  " + GlQueryVOAssTool.getPages(qryvo) + " 页");
            Logger.info("*************************************************");
            return this.queryMultiPage2(qryvo);
        }
    }

    private Map<String, Object> queryOnePage2(GlQueryVO qryvo) throws Exception {
        GlQueryVOAssTool.suplyCurrentGlQueryVO(qryvo);
        GlQueryVOAssTool.getSuplyedGLQueryObj(qryvo.getFormatVO().getQryObjs());
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        BalanceSubjAssBSVO[] bvos = (BalanceSubjAssBSVO[])blnsbjAssMdl.dealQueryAssBalance(qryvo);
        Map<String, Object> res = this.getRes(qryvo);
        List<Map<String, Object>> pages = new ArrayList();
        Map<String, Object> page = new HashMap();
        page.put("pagedata", bvos);
        pages.add(page);
        res.put("data", pages);
        return res;
    }

    private Map<String, Object> queryMultiPage2(GlQueryVO qryvo) throws Exception {
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        GlQueryVOContainer glQryCtner = blnsbjAssMdl.getQueryVOContainer(qryvo);
        if (glQryCtner != null) {
            for(int i = 0; i < glQryCtner.getSize(); ++i) {
                if (glQryCtner.getQueryAt(i) != null) {
                    glQryCtner.getQueryAt(i).setGlChartConditionVO(qryvo.getGlChartConditionVO());
                }
            }
        }

        List<Map<String, Object>> pages = new ArrayList();
        if (glQryCtner.getSize() > 0) {
            BalanceSubjAssBSVO[] allBvos = (BalanceSubjAssBSVO[])glQryCtner.getVos();
            if (allBvos != null) {
                BlnSbjAssMdlSttl blnSbjAssMdlSttl = new BlnSbjAssMdlSttl();

                for(Object key : glQryCtner.getVKeys()) {
                    String assCode = (String)key;
                    GlQueryVO copyStartQryvo = (GlQueryVO)qryvo.clone();
                    GlQueryVOAssTool.suplyCurrentGlQueryVO(copyStartQryvo);
                    GlQueryVO tempQryVO = GlQueryVOAssTool.getGlQueryVOMultiPage(copyStartQryvo, assCode);
                    BalanceSubjAssBSVO[] tempBvos = AssBlcResultGetter.getBlnVOsByQryVOs(assCode, allBvos);
                    tempBvos = blnSbjAssMdlSttl.getSettleedDatas(tempBvos, tempQryVO);
                    Map<String, Object> page = new HashMap();
                    page.put("pageinfo", this.getHeadKeyName(tempQryVO));
                    page.put("pagedata", tempBvos);
                    pages.add(page);
                }
            } else {
                for(int i = 0; i < glQryCtner.getVKeys().size(); ++i) {
                    GlQueryVO tempQryVO = glQryCtner.getQueryAt(i);
                    BalanceSubjAssBSVO[] tempBvos = (BalanceSubjAssBSVO[])glQryCtner.getBalaceVOsAt(i);
                    Map<String, Object> page = new HashMap();
                    page.put("pageinfo", this.getHeadKeyName(tempQryVO));
                    page.put("pagedata", tempBvos);
                    pages.add(page);
                }
            }
        }

        Map<String, Object> res = this.getRes(qryvo);
        res.put("data", pages);
        return res;
    }

    private Map<String, Object> queryMultiPage(GlQueryVO qryvo) throws Exception {
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        GlQueryVOContainer glQryCtner = blnsbjAssMdl.getQueryVOContainer(qryvo);
        if (glQryCtner != null) {
            for(int i = 0; i < glQryCtner.getSize(); ++i) {
                if (glQryCtner.getQueryAt(i) != null) {
                    glQryCtner.getQueryAt(i).setGlChartConditionVO(qryvo.getGlChartConditionVO());
                }
            }
        }

        boolean showPageLength = false;
        List<Map<String, Object>> pages = new ArrayList();
        if (glQryCtner != null && glQryCtner.getSize() > 0) {
            showPageLength = true;
            BalanceSubjAssBSVO[] allBvos = (BalanceSubjAssBSVO[])glQryCtner.getVos();
            if (allBvos != null) {
                BlnSbjAssMdlSttl blnSbjAssMdlSttl = new BlnSbjAssMdlSttl();

                for(Object key : glQryCtner.getVKeys()) {
                    String assCode = (String)key;
                    GlQueryVO copyStartQryvo = (GlQueryVO)qryvo.clone();
                    GlQueryVOAssTool.suplyCurrentGlQueryVO(copyStartQryvo);
                    GlQueryVO tempQryVO = GlQueryVOAssTool.getGlQueryVOMultiPage(copyStartQryvo, assCode);
                    BalanceSubjAssBSVO[] tempBvos = AssBlcResultGetter.getBlnVOsByQryVOs(assCode, allBvos);
                    tempBvos = blnSbjAssMdlSttl.getSettleedDatas(tempBvos, tempQryVO);
                    Map<String, Object> page = new HashMap();
                    List<Map<String, Object>> data = this.getData(copyStartQryvo, tempBvos);
                    page.put("pageinfo", this.getHeadKeyName(tempQryVO));
                    page.put("pagedata", data);
                    pages.add(page);
                }
            } else {
                for(int i = 0; i < glQryCtner.getVKeys().size(); ++i) {
                    GlQueryVO tempQryVO = glQryCtner.getQueryAt(i);
                    BalanceSubjAssBSVO[] tempBvos = (BalanceSubjAssBSVO[])glQryCtner.getBalaceVOsAt(i);
                    Map<String, Object> page = new HashMap();
                    List<Map<String, Object>> data = this.getData(tempQryVO, tempBvos);
                    page.put("pageinfo", this.getHeadKeyName(tempQryVO));
                    page.put("pagedata", data);
                    pages.add(page);
                }
            }
        } else {
            Map<String, Object> page = new HashMap();
            page.put("pageinfo", "");
            page.put("pagedata", "");
            pages.add(page);
        }

        Map<String, Object> res = this.getRes(qryvo);
        res.put("data", pages);
        res.put("showpagelength", showPageLength);
        return res;
    }

    private String getHeadKeyName(GlQueryVO qryvo) {
        String headKeyName = "";
        GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();

        for(int i = 0; i < queryObjs.length; ++i) {
            GLQueryObj queryObj = queryObjs[i];
            if (queryObj.getHeadEle()) {
                if (queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031"))) {
                    String subjName = ShowContentCenter.getShowAccsubj(qryvo.getBaseAccountingbook(), qryvo.getPk_account()[0], qryvo.getSubjVersion());
                    headKeyName = NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000135") + subjName + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000136") + headKeyName;
                } else {
                    String pk_checktype = "";
                    if (queryObj.getValueRange() != null && queryObj.getValueRange()[0] != null) {
                        pk_checktype = queryObj.getValueRange()[0].getPk_Checktype();
                    }

                    if (!StrTools.isEmptyStr(pk_checktype) && (qryvo.getAssVos() != null || qryvo.getAssVos().length > 0)) {
                        for(AssVO assvo : qryvo.getAssVos()) {
                            if (pk_checktype.equals(assvo.getPk_Checktype())) {
                                headKeyName = headKeyName + ShowContentCenter.getShowAss(qryvo.getBaseAccountingbook(), new AssVO[]{assvo});
                            }
                        }
                    }
                }
            }
        }

        return headKeyName;
    }

    private Map<String, Object> queryOnePage(GlQueryVO qryvo) throws Exception {
        GlQueryVOAssTool.suplyCurrentGlQueryVO(qryvo);
        GlQueryVOAssTool.getSuplyedGLQueryObj(qryvo.getFormatVO().getQryObjs());
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        BalanceSubjAssBSVO[] bvos = (BalanceSubjAssBSVO[])blnsbjAssMdl.dealQueryAssBalance(qryvo);
        Map<String, Object> res = this.getRes(qryvo);
        List<Map<String, Object>> pages = new ArrayList();
        Map<String, Object> page = new HashMap();
        page.put("pagedata", this.getData(qryvo, bvos));
        pages.add(page);
        res.put("data", pages);
        res.put("showpagelength", false);
        return res;
    }

    private void fillParamMap(Map<String, Object> params) throws BusinessException {
        String companyPK = (String)((Map)params.get("companychoose")).get("pk_org");
        String accountingPeriod = JsonUtils.getStrEmpty(params.get("accountingPeriod"));
        String auxiliaryFiles = JsonUtils.getStrEmpty(params.get("auxiliaryFiles"));
        String accountSubject = JsonUtils.getStrNULL(params.get("accountSubject"));
        List<String> accountingbook_pks = new ArrayList();
        String pk_accountingbook = AccountRepUtil.getAccountingbookPKByOrgPK(companyPK);
        accountingbook_pks.add(pk_accountingbook);
        UFDate bizDate = new UFDate(InvocationInfoProxy.getInstance().getBizDateTime());
        AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(pk_accountingbook);
        calendar.setDate(bizDate);
        String periodyear = calendar.getYearVO().getPeriodyear();
        if (!StrTools.isEmptyStr(accountingPeriod) && accountingPeriod.length() <= 40 && accountingPeriod.matches("\\d{6}-\\d{6}[^\\s]*")) {
            String[] splitPeriod = accountingPeriod.split("-");
            String year_begin = splitPeriod[0].substring(0, 4);
            String year_end = splitPeriod[1].substring(0, 4);
            String period_begin = splitPeriod[0].substring(4);
            String period_end = splitPeriod[1].substring(4);
            if (StrTools.isEmptyStr(year_begin)) {
                year_begin = periodyear;
            }

            if (StrTools.isEmptyStr(year_end)) {
                year_end = year_begin;
            }

            if (StrTools.isEmptyStr(period_begin)) {
                period_begin = calendar.getMonthVO().getAccperiodmth();
            }

            if (StrTools.isEmptyStr(period_end)) {
                period_end = period_begin;
            }

            String commaEn = ",";
            String commaCh = "，";
            String[] itemname = auxiliaryFiles.contains(commaEn) ? auxiliaryFiles.split(commaEn) : auxiliaryFiles.split(commaCh);
            params.put("pk_glorgbooks", accountingbook_pks);
            params.put("selectionState", true);
            params.put("beginyear", year_begin);
            params.put("endyear", year_end);
            params.put("beginperiod", period_begin);
            params.put("endperiod", period_end);
            params.put("includeUnTallyed", true);
            params.put("includeError", true);
            params.put("includeTransfer", true);
            params.put("includeReClassify", false);
            params.put("currTypeName", CurrTypeConst.QUERY_LOC_CURRTYPE());
            params.put("return_currtype", 1);
            params.put("balanceDirection", -1);
            List<Map<String, Object>> qryObjs = new ArrayList();
            Map<String, Object> accountQryObj = new HashMap(6);
            String MultiLang_Account = NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031");
            accountQryObj.put("name", MultiLang_Account);
            accountQryObj.put("pk_checktype", MultiLang_Account);
            if (!StrTools.isEmptyStr(accountSubject)) {
                StringBuilder pk_accasoa = new StringBuilder();
                if (accountSubject.contains("-")) {
                    String[] accountScope = accountSubject.split("-");
                    AccountGLSimpleVO[] accvos = AccountUtilGL.querySimpleAccountVOs(new String[]{pk_accountingbook}, accountScope[0], accountScope[1], "1", "1", true, false, AccountRepUtil.getPowerCond(), bizDate.toString());
                    if (accvos == null || accvos.length <= 0) {
                        String var10002 = NCLangRes4VoTransl.getNCLangRes().getStrByID("20021101", "UPP20021101-000264");
                        throw new BusinessException(var10002 + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000230") + accountSubject + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021201", "UPP20021201-000322"));
                    }

                    for(AccountGLSimpleVO accvo : accvos) {
                        pk_accasoa.append(accvo.getPk_accasoa()).append(commaEn);
                    }
                } else {
                    accountSubject = accountSubject.replaceAll(" ", "");
                    String[] accountCodes = accountSubject.contains(commaCh) ? accountSubject.split(commaCh) : accountSubject.split(commaEn);
                    Map<String, String> accountCodesMap = new Hashtable(accountCodes.length);

                    for(String code : accountCodes) {
                        accountCodesMap.put(code, "");
                    }

                    AccountVO[] accvos = AccountByPkThreadCache.getInstance().getAccountVOByCodes(pk_accountingbook, accountCodes, bizDate.toString());
                    if (accvos != null && accvos.length > 0) {
                        for(AccountVO accvo : accvos) {
                            if (accvo != null) {
                                pk_accasoa.append(accvo.getPk_accasoa()).append(commaEn);
                                accountCodesMap.remove(accvo.getCode());
                            }
                        }
                    }

                    if (!accountCodesMap.isEmpty()) {
                        StringBuilder errAccCode = new StringBuilder();

                        for(String code : accountCodesMap.keySet()) {
                            errAccCode.append(code).append(commaEn);
                        }

                        errAccCode.deleteCharAt(errAccCode.length() - 1);
                        String var55 = NCLangRes4VoTransl.getNCLangRes().getStrByID("20021101", "UPP20021101-000264");
                        throw new BusinessException(var55 + errAccCode.toString() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021505", "UPP20021505-000146"));
                    }
                }

                if (pk_accasoa.length() > 0) {
                    pk_accasoa.deleteCharAt(pk_accasoa.length() - 1);
                }

                accountQryObj.put("pk_checkvalue", pk_accasoa.toString());
            }

            accountQryObj.put("headEle", false);
            accountQryObj.put("accEle", false);
            accountQryObj.put("includeSub", false);
            qryObjs.add(accountQryObj);
            if (itemname != null && itemname.length > 0) {
                IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor("d3f0e93b-9234-44b9-83c1-6e05bf1e9a28");
                String groupId = InvocationInfoProxy.getInstance().getGroupId();
                StringBuilder errChecktype = new StringBuilder();

                for(String checktypename : itemname) {
                    checktypename = checktypename.trim();
                    if (!StrTools.isEmptyStr(checktypename)) {
                        IBDData bdData = accessor.getDocByNameWithMainLang(groupId, checktypename);
                        if (bdData == null) {
                            errChecktype.append(checktypename).append(commaEn);
                        }

                        if (errChecktype.length() == 0) {
                            Map<String, Object> qryObj = new HashMap(6);
                            qryObj.put("name", bdData.getName().toString());
                            qryObj.put("pk_checktype", bdData.getPk());
                            qryObj.put("pk_checkvalue", "");
                            qryObj.put("headEle", false);
                            qryObj.put("accEle", false);
                            qryObj.put("includeSub", false);
                            qryObjs.add(qryObj);
                        }
                    }
                }

                if (errChecktype.length() > 0) {
                    errChecktype.deleteCharAt(errChecktype.length() - 1);
                    String var54 = NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000058");
                    throw new BusinessException(var54 + errChecktype.toString() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021505", "UPP20021505-000146"));
                }
            }

            params.put("qryObjs", qryObjs);
        } else {
            throw new BusinessException("会计期间格式不正确！请按照如下示例：" + periodyear + "01-" + periodyear + "03");
        }
    }

    public GlQueryVO getQueryVO(Map<String, Object> params) throws BusinessException {
        if (params.containsKey("companyName")) {
            this.fillParamMap(params);
        }

        GlQueryVO qryVO = new GlQueryVO();
        String[] pk_glorgbooks = JsonUtils.getStrArray(params.get("pk_glorgbooks"));
        if (pk_glorgbooks != null && pk_glorgbooks.length != 0) {
            String pk_accountingbook = pk_glorgbooks[0];
            String newBase = BaseCorpChooser.getPk_BasCorp(pk_glorgbooks, pk_accountingbook);
            qryVO.setBaseAccountingbook(newBase);
            if (pk_glorgbooks == null || pk_glorgbooks.length == 0) {
                pk_glorgbooks = new String[]{pk_accountingbook};
            }

            qryVO.setpk_accountingbook(pk_glorgbooks);
            GlQryFormatVO qryFormatVo = qryVO.getFormatVO();
            qryVO.setQueryByPeriod(JsonUtils.getBoolean(params.get("selectionState")));
            if (params.get("isprint") != null && (Boolean)params.get("isprint")) {
                qryVO.setPrint(Boolean.TRUE);
            }

            if (qryVO.isQueryByPeriod()) {
                qryVO.setYear(JsonUtils.getStrNULL(params.get("beginyear")));
                qryVO.setPeriod(JsonUtils.getStrNULL(params.get("beginperiod")));
                qryVO.setEndYear(JsonUtils.getStrNULL(params.get("endyear")));
                qryVO.setEndPeriod(JsonUtils.getStrNULL(params.get("endperiod")));
                if (!StrTools.isEmptyStr(qryVO.getYear()) && !StrTools.isEmptyStr(qryVO.getEndYear()) && !StrTools.isEmptyStr(qryVO.getPeriod()) && !StrTools.isEmptyStr(qryVO.getEndPeriod())) {
                    AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(qryVO.getBaseAccountingbook());
                    calendar.set(qryVO.getYear(), qryVO.getPeriod());
                    qryVO.setDate(calendar.getMonthVO().getBegindate());
                    calendar.set(qryVO.getEndYear(), qryVO.getEndPeriod().substring(0, 2));
                    qryVO.setEndDate(calendar.getMonthVO().getEnddate().asEnd());
                }
            } else {
                if (StrTools.isEmptyStr(JsonUtils.getStrNULL(params.get("begindate"))) || StrTools.isEmptyStr(JsonUtils.getStrNULL(params.get("enddate")))) {
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000521"));
                }

                UFDate startDate = AccountRepUtil.getStdStartDate(JsonUtils.getStrNULL(params.get("begindate")));
                UFDate endDate = AccountRepUtil.getStdEndDate(JsonUtils.getStrNULL(params.get("enddate")));
                AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(newBase);
                String[] startPeiod = AccountBookUtil.getStartPeriod(newBase);

                try {
                    calendar.set(startPeiod[0], startPeiod[1]);
                } catch (InvalidAccperiodExcetion e) {
                    Logger.error(e.getMessage(), e);
                }

                UFDate accountBookstartDate = calendar.getMonthVO().getBegindate();
                UFDate accountBookEndDate = calendar.getMonthVO().getEnddate();
                if (startDate.before(accountBookstartDate)) {
                    qryVO.setDate(accountBookstartDate);
                } else {
                    qryVO.setDate(startDate);
                }

                qryVO.setEndDate(endDate);
                if (qryVO.getDate() != null && qryVO.getEndDate() != null) {
                    calendar.setDate(qryVO.getDate());
                    qryVO.setYear(calendar.getYearVO().getPeriodyear());
                    qryVO.setPeriod(calendar.getMonthVO().getAccperiodmth());
                    calendar.setDate(qryVO.getEndDate());
                    qryVO.setEndYear(calendar.getYearVO().getPeriodyear());
                    qryVO.setEndPeriod(calendar.getMonthVO().getAccperiodmth());
                }
            }

            qryVO.setUserData(new String[]{qryVO.getYear(), qryVO.getPeriod()});
            qryVO.setIncludeUnTallyed(JsonUtils.getBoolean(params.get("includeUnTallyed")));
            qryVO.setIncludeError(JsonUtils.getBoolean(params.get("includeError")));
            qryVO.setIncludeTransfer(JsonUtils.getBoolean(params.get("includeTransfer")));
            qryVO.setIncludeReClassify(JsonUtils.getBoolean(params.get("includeReClassify")));
            qryVO.setCurrTypeName(JsonUtils.getStrNULL(params.get("currTypeName")));
            qryVO.setM_Return_CurrType(JsonUtils.getInteger(params.get("return_currtype")));
            qryVO.setLocalFrac(false);
            if (!qryVO.getCurrTypeName().equals(CurrTypeConst.AUX_CURRTYPE()) && !qryVO.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE()) && !qryVO.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
                qryVO.setPk_currtype(JsonUtils.getStrNULL(params.get("pk_currtype")));
            } else {
                qryVO.setPk_currtype((String)null);
                if (qryVO.getCurrTypeName().equals(CurrTypeConst.AUX_CURRTYPE())) {
                    qryVO.setLocalFrac(true);
                }
            }

            if (qryVO.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
                qryVO.setLocalFrac(this.isLocalFrac(pk_accountingbook));
            }

            qryFormatVo.setMultiCorpCombine(JsonUtils.getBoolean(params.get("rbCorpJun")));
            qryFormatVo.setBalanceOrient(JsonUtils.getInteger(params.get("balanceDirection")));
            if (params.get("balanceRangeFrom") != null) {
                qryFormatVo.setBalanceRangeFrom(new UFDouble(params.get("balanceRangeFrom").toString()));
            }

            if (params.get("balanceRangeTo") != null) {
                qryFormatVo.setBalanceRangeTo(new UFDouble(params.get("balanceRangeTo").toString()));
            }

            qryFormatVo.setCorpDispLocation(JsonUtils.getBoolean(params.get("qryObjPlusCorp")) ? 0 : 1);
            qryFormatVo.setIsSubjSelectAll(true);
            qryFormatVo.setSortType(0);
            qryFormatVo.setIsCorpSubjDspBase(!JsonUtils.getBoolean(params.get("cbCorpSubjDspBase")));
            qryFormatVo.setIsQryByCorpAss(JsonUtils.getBoolean(params.get("cbQryByCorpAss")));
            qryFormatVo.setShowDayAcc(false);
            qryFormatVo.setShowYearAcc(false);
            qryFormatVo.setCombineVoucher(false);
            qryFormatVo.setTwoWayBalance(JsonUtils.getBoolean(params.get("twowaybalance")));
            qryFormatVo.setShowHasBalanceButZeroOccur(!JsonUtils.getBoolean(params.get("ckShowZeroAmount")));
            qryFormatVo.setShowHasBalanceButZeroOccur(!UFBoolean.valueOf(params.get("ckShowZeroAmount").toString()).booleanValue());
            qryFormatVo.setShowZeroAmountRec(!UFBoolean.valueOf(params.get("ckNotShowZeroOccurZeroBalance").toString()).booleanValue());
            if (params.get("ckShowZeroBalance") != null) {
                qryFormatVo.setShowZeroBalance(!UFBoolean.valueOf(params.get("ckShowZeroBalance").toString()).booleanValue());
            }

            qryVO.setFormatVO(qryFormatVo);
            Object[] pk_orgs = JsonUtils.getStrArray(params.get("pk_orgs"));
            String[] pk_units = null;
            if (pk_glorgbooks.length == 1) {
                if (pk_orgs != null && pk_orgs.length > 0) {
                    pk_units = new String[pk_orgs.length];

                    for(int i = 0; i < pk_orgs.length; ++i) {
                        pk_units[i] = pk_orgs[i].toString();
                    }
                } else {
                    pk_units = AccountRepUtil.getPowerUnits(pk_glorgbooks[0]);
                }
            }

            String[] pk_liabilitycenteros = params.get("pk_liabilitycenter") != null && !params.get("pk_liabilitycenter").equals("") ? (String[])((List)params.get("pk_liabilitycenter")).toArray(new String[0]) : null;
            String[] pk_liabilitycenters = null;
            if (pk_glorgbooks.length == 1 && pk_liabilitycenteros != null && pk_liabilitycenteros.length > 0) {
                pk_liabilitycenters = new String[pk_liabilitycenteros.length];

                for(int i = 0; i < pk_liabilitycenteros.length; ++i) {
                    pk_liabilitycenters[i] = pk_liabilitycenteros[i].toString();
                }
            }

            qryVO.setPk_liabilitycenters(pk_liabilitycenters);
            qryVO.setPk_unis(pk_units);
            qryVO.setMultiLiabcenter(params.get("multliabcenter") == null ? false : UFBoolean.valueOf(params.get("multliabcenter").toString()).booleanValue());
            qryVO.setMultiBusi(JsonUtils.getBoolean(params.get("multiBusi")));
            qryVO.setMultiYearMerge(JsonUtils.getBoolean(params.get("multiYearMerge")));
            UFDate busiDate = new UFDate(InvocationInfoProxy.getInstance().getBizDateTime());
            qryVO.setPk_user(InvocationInfoProxy.getInstance().getUserId());
            qryVO.setDefaultAdjust(false);
            qryVO.setDisLocalCurySum(false);
            qryVO.setUseSubjVersion(JsonUtils.getBoolean(params.get("useSubjVersion")));
            if (qryVO.isUseSubjVersion()) {
                qryVO.setSubjVersion(JsonUtils.getStrNULL(params.get("subjVersion")));
            } else {
                qryVO.setSubjVersionYear("" + busiDate.getYear());
                qryVO.setSubjVerisonPeriod(busiDate.getStrMonth());
                qryVO.setSubjVersion(busiDate.toStdString());
            }

            this.setQryObjs(qryVO, params.get("qryObjs"));
            qryVO.setShowBusinessDate(false);
            qryVO.setPk_fccurrtype(params.get("pk_fccurrtype") != null ? params.get("pk_fccurrtype").toString() : null);
            qryVO.setFcrate(params.get("fcrate") != null ? params.get("fcrate").toString() : null);
            return qryVO;
        } else {
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0019"));
        }
    }

    private Boolean isLocalFrac(String strPk_orgbook) {
        try {
            if (strPk_orgbook.equals("0001")) {
                UFBoolean blnTemp = UFBoolean.valueOf(SysinitAccessor.getInstance().getParaString(strPk_orgbook, "BD212").toString());
                return new Boolean(blnTemp.booleanValue());
            } else {
                return AccountBookUtil.getSetOfBookVOByPk_accountingBook(strPk_orgbook).getPk_standardcurr() == null ? new Boolean(true) : new Boolean(false);
            }
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            return Boolean.FALSE;
        }
    }

    private void setQryObjs(GlQueryVO qryVO, Object json) throws BusinessException {
        if (json != null) {
            Set<String> checktypeList = new HashSet();
            List<GLQueryObj> glQueryObjs = new ArrayList();
            List<Object> list = (List)json;

            for(int i = 0; i < list.size(); ++i) {
                Map<String, Object> qryObjMap = (Map)list.get(i);
                if (!StrTools.isEmptyStr(JsonUtils.getStrNULL(qryObjMap.get("name"))) && !NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031").equals(JsonUtils.getStrNULL(qryObjMap.get("name")))) {
                    checktypeList.add(JsonUtils.getStrNULL(qryObjMap.get("pk_checktype")));
                }
            }

            for(int i = 0; i < list.size(); ++i) {
                Map<String, Object> qryObjMap = (Map)list.get(i);
                if (!StrTools.isEmptyStr(JsonUtils.getStrNULL(qryObjMap.get("name")))) {
                    GLQueryObj glQueryObj = new GLQueryObj();
                    glQueryObj.setAccEle(JsonUtils.getBoolean(qryObjMap.get("accEle")));
                    glQueryObj.setAttrsValues((AttrsValueVO[])null);
                    glQueryObj.setHeadEle(JsonUtils.getBoolean(qryObjMap.get("headEle")));
                    glQueryObj.setIncludeSub(JsonUtils.getBoolean(qryObjMap.get("includeSub")));
                    glQueryObj.setLinkObj((Object)null);
                    glQueryObj.setDirty(false);
                    glQueryObj.setType(JsonUtils.getStrNULL(qryObjMap.get("name")));
                    glQueryObj.setTypeName(JsonUtils.getStrNULL(qryObjMap.get("name")));
                    String pk_checkvalues = JsonUtils.getStrNULL(qryObjMap.get("pk_checkvalue"));
                    if (NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031").equals(JsonUtils.getStrNULL(qryObjMap.get("name")))) {
                        if (pk_checkvalues != null && pk_checkvalues.length() > 0) {
                            AccountVO[] accvos = AccountUtilGL.queryAccountVosByPks(pk_checkvalues.split(","), qryVO.getSubjVersion(), false);
                            if (accvos != null && accvos.length > 0) {
                                Arrays.sort(accvos, new Comparator<AccountVO>() {
                                    public int compare(AccountVO o1, AccountVO o2) {
                                        return o1.getCode().compareTo(o2.getCode());
                                    }
                                });
                                AssVO[] accounts = new AssVO[accvos.length];

                                for(int j = 0; j < accvos.length; ++j) {
                                    accounts[j] = new AssVO();
                                    accounts[j].setCheckvaluecode(accvos[j].getCode());
                                    accounts[j].setCheckvaluename(accvos[j].getName());
                                    accounts[j].setPk_Checkvalue(accvos[j].getPk_accasoa());
                                }

                                glQueryObj.setValueRange(accounts);
                            }
                        } else {
                            AccountGLSimpleVO[] accvos = AccountUtilGL.queryAccByAss((String[])checktypeList.toArray(new String[0]), qryVO.getBaseAccountingbook(), qryVO.getSubjVersion());
                            if (accvos != null && accvos.length > 0) {
                                Arrays.sort(accvos, new Comparator<AccountGLSimpleVO>() {
                                    public int compare(AccountGLSimpleVO o1, AccountGLSimpleVO o2) {
                                        return o1.getCode().compareTo(o2.getCode());
                                    }
                                });
                                AssVO[] accounts = new AssVO[accvos.length];

                                for(int j = 0; j < accvos.length; ++j) {
                                    accounts[j] = new AssVO();
                                    accounts[j].setCheckvaluecode(accvos[j].getCode());
                                    accounts[j].setCheckvaluename(accvos[j].getName());
                                    accounts[j].setPk_Checkvalue(accvos[j].getPk_accasoa());
                                }

                                glQueryObj.setValueRange(accounts);
                            }
                        }

                        if (glQueryObj.getValueRange() == null) {
                            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000198"));
                        }
                    } else {
                        String pk_checktype = JsonUtils.getStrNULL(qryObjMap.get("pk_checktype"));
                        AccAssItemVO accassItemVO = AccAssGL.getAccAssItemVOByPk(pk_checktype);
                        if (accassItemVO == null) {
                            Logger.error("assbalance: invalid pk_checktype:" + pk_checktype);
                            continue;
                        }

                        String checktypename = GLMultiLangUtil.getMultiName(accassItemVO);
                        String checktypecode = accassItemVO.getCode();
                        String classid = AccAssGL.getClassidByCheckTypePk(pk_checktype);
                        if (!StrTools.isEmptyStr(pk_checkvalues)) {
                            String[] arrCheckvalues = pk_checkvalues.split(",");
                            AssVO[] assvos = new AssVO[arrCheckvalues.length];

                            for(int j = 0; j < assvos.length; ++j) {
                                assvos[j] = new AssVO();
                                assvos[j].setPk_Checktype(pk_checktype);
                                assvos[j].setChecktypename(checktypename);
                                assvos[j].setChecktypecode(checktypecode);
                                assvos[j].setM_classid(classid);
                            }

                            if (FreeValueDefUtil.getInstance().isDefDoc(classid)) {
                                for(int j = 0; j < assvos.length; ++j) {
                                    assvos[j].setPk_Checkvalue(arrCheckvalues[j]);
                                    assvos[j].setCheckvaluecode(arrCheckvalues[j]);
                                    assvos[j].setCheckvaluename(arrCheckvalues[j]);
                                }
                            } else {
                                IGeneralAccessor accessor = (new AssAccessorManager()).getDBAccess(classid);
                                IBDData[] datas = accessor.getDocbyPks(arrCheckvalues);
                                Map<String, IBDData> map = new HashMap();

                                for(IBDData data : datas) {
                                    map.put(data.getPk(), data);
                                }

                                for(int j = 0; j < assvos.length; ++j) {
                                    assvos[j].setPk_Checkvalue(arrCheckvalues[j]);
                                    assvos[j].setCheckvaluecode(((IBDData)map.get(arrCheckvalues[j])).getCode());
                                    assvos[j].setCheckvaluename(((IBDData)map.get(arrCheckvalues[j])).getName().getText());
                                }
                            }

                            glQueryObj.setValueRange(assvos);
                        } else {
                            AssVO[] assvos = new AssVO[1];
                            assvos[0] = new AssVO();
                            assvos[0].setPk_Checktype(pk_checktype);
                            assvos[0].setCheckvaluename("ALL");
                            assvos[0].setChecktypename(checktypename);
                            assvos[0].setChecktypecode(checktypecode);
                            glQueryObj.setValueRange(assvos);
                        }
                    }

                    glQueryObjs.add(glQueryObj);
                }
            }

            qryVO.getFormatVO().setQryObjs((GLQueryObj[])glQueryObjs.toArray(new GLQueryObj[glQueryObjs.size()]));
        }
    }

    private Map<String, Object> getRes(GlQueryVO qryvo) throws Exception {
        Map<String, Object> result = new HashMap();
        result.put("column", this.getColumn(qryvo));
        Map<String, String> headTitle = new HashMap();
        headTitle.put("accbook", AccountRepUtil.getOrgNames(qryvo));
        headTitle.put("period", qryvo.isQueryByPeriod() ? qryvo.getYear() + "-" + qryvo.getPeriod() + "--" + qryvo.getEndYear() + "-" + qryvo.getEndPeriod() : DataFormatUtilGL.formatDate(qryvo.getDate()).getValue() + "--" + DataFormatUtilGL.formatDate(qryvo.getEndDate()).getValue());
        headTitle.put("currtype", qryvo.getCurrTypeName());
        headTitle.put("loccurrtype", qryvo.getReturn_CurrtypeName());
        if (!StrTools.isEmptyStr(qryvo.getPk_fccurrtype())) {
            CurrtypeVO currtypeVO = CurrtypeGL.findByPrimaryKey(qryvo.getPk_fccurrtype().toString());
            if (currtypeVO != null) {
                headTitle.put("loccurrtype", GLMultiLangUtil.getMultiName(currtypeVO));
            }
        }

        result.put("headtitle", headTitle);
        return result;
    }

    public List<Map<String, Object>> getData(GlQueryVO qryvo, BalanceSubjAssBSVO[] vos) throws Exception {
        List<Map<String, Object>> data = new ArrayList();
        if (vos != null && vos.length != 0) {
            this.setPk_localcurr(AccountRepUtil.getLocalCurr(qryvo));
            boolean isMultiPages = GlQueryVOAssTool.isMultiPages(qryvo);
            this.processUnitName(qryvo, vos);
            this.adjustLiabilitycenterVersion(qryvo, vos);
            Map<String, String> assIndexMap = new HashMap();
            GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();

            for(int i = 0; i < queryObjs.length; ++i) {
                GLQueryObj queryObj = queryObjs[i];
                AssVO[] assvos = queryObj.getValueRange();
                if (assvos != null && assvos.length > 0 && assvos[0] != null) {
                    assIndexMap.put(assvos[0].getPk_Checktype(), "" + i);
                }
            }

            boolean isExistsMaterial = this.isExistsMaterial(qryvo);
            Map<String, String> materialMeasdocMap = null;
            if (isExistsMaterial) {
                materialMeasdocMap = this.getMaterialMeasdoc(vos);
            }

            for(BalanceSubjAssBSVO vo : vos) {
                String pk_currtype = (String)vo.getValue(49);
                String pk_currtype_amount = (pk_currtype == null || pk_currtype.length() != 20 || "ZZZZZZZZZZZZZZZZZZZZ".equals(pk_currtype) || "99999999999999999999".equals(pk_currtype)) && qryvo.getPk_currtype() != null && !CurrTypeConst.ALL_CURRTYPE().equals(qryvo.getPk_currtype()) && !CurrTypeConst.QUERY_LOC_CURRTYPE().equals(qryvo.getPk_currtype()) ? qryvo.getPk_currtype() : this.pk_localcurr;
                Map<String, Object> row = new HashMap();
                row.put("pk_accountingbook", vo.getValue(102));
                Object mark = vo.getValue(90);
                row.put("mark", mark);
                row.put("year", vo.getValue(43));
                String pk_accountingbook = (String)vo.getValue(102);
                row.put("bookname", "9999".equals(pk_accountingbook) ? "" : AccountBookUtil.getAccountingBookNameByPk(pk_accountingbook));
                row.put("unitname", vo.getValue(100));
                row.put("liabilitycentername", vo.getValue(138));
                row.put("accsubjcode", vo.getValue(45));
                row.put("accsubjname", vo.getValue(46));
                row.put("measureunit", vo.getValue(200));
                row.put("curtype", vo.getValue(2));
                row.put("initorients", vo.getValue(235));
                if (!StrTools.isEmptyStr(qryvo.getPk_fccurrtype()) && !StrTools.isEmptyStr(qryvo.getFcrate())) {
                    UFDouble fcrate = new UFDouble(qryvo.getFcrate());
                    row.put("initamount", this.format.getFormatAmountVlaue(vo.getValue(61), vo, pk_currtype_amount));
                    row.put("initlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(63), fcrate), this.pk_localcurr));
                    row.put("initdebitamount", this.format.getFormatAmountVlaue(vo.getValue(4), vo, pk_currtype_amount));
                    row.put("initdebitlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(6), fcrate), this.pk_localcurr));
                    row.put("initcreditamount", this.format.getFormatAmountVlaue(vo.getValue(8), vo, pk_currtype_amount));
                    row.put("initcreditlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(10), fcrate), this.pk_localcurr));
                    row.put("debitamount", this.format.getFormatAmountVlaue(vo.getValue(12), vo, pk_currtype_amount));
                    row.put("debitlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(14), fcrate), this.pk_localcurr));
                    row.put("creditamount", this.format.getFormatAmountVlaue(vo.getValue(16), vo, pk_currtype_amount));
                    row.put("creditlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(18), fcrate), this.pk_localcurr));
                    row.put("debitaccumamount", this.format.getFormatAmountVlaue(vo.getValue(20), vo, pk_currtype_amount));
                    row.put("debitaccumlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(22), fcrate), this.pk_localcurr));
                    row.put("creditaccumamount", this.format.getFormatAmountVlaue(vo.getValue(24), vo, pk_currtype_amount));
                    row.put("creditaccumlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(26), fcrate), this.pk_localcurr));
                    row.put("endamount", this.format.getFormatAmountVlaue(vo.getValue(65), vo, pk_currtype_amount));
                    row.put("endlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(67), fcrate), this.pk_localcurr));
                    row.put("enddebitamount", this.format.getFormatAmountVlaue(vo.getValue(28), vo, pk_currtype_amount));
                    row.put("enddebitlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(30), fcrate), this.pk_localcurr));
                    row.put("endcreditamount", this.format.getFormatAmountVlaue(vo.getValue(32), vo, pk_currtype_amount));
                    row.put("endcreditlocamount", this.format.getFormatLocalVlaue(this.multiplyCalculation(vo.getValue(34), fcrate), this.pk_localcurr));
                } else {
                    row.put("initamount", this.format.getFormatAmountVlaue(vo.getValue(61), vo, pk_currtype_amount));
                    row.put("initlocamount", this.format.getFormatLocalVlaue(vo.getValue(63), this.pk_localcurr));
                    row.put("initdebitamount", this.format.getFormatAmountVlaue(vo.getValue(4), vo, pk_currtype_amount));
                    row.put("initdebitlocamount", this.format.getFormatLocalVlaue(vo.getValue(6), this.pk_localcurr));
                    row.put("initcreditamount", this.format.getFormatAmountVlaue(vo.getValue(8), vo, pk_currtype_amount));
                    row.put("initcreditlocamount", this.format.getFormatLocalVlaue(vo.getValue(10), this.pk_localcurr));
                    row.put("debitamount", this.format.getFormatAmountVlaue(vo.getValue(12), vo, pk_currtype_amount));
                    row.put("debitlocamount", this.format.getFormatLocalVlaue(vo.getValue(14), this.pk_localcurr));
                    row.put("creditamount", this.format.getFormatAmountVlaue(vo.getValue(16), vo, pk_currtype_amount));
                    row.put("creditlocamount", this.format.getFormatLocalVlaue(vo.getValue(18), this.pk_localcurr));
                    row.put("debitaccumamount", this.format.getFormatAmountVlaue(vo.getValue(20), vo, pk_currtype_amount));
                    row.put("debitaccumlocamount", this.format.getFormatLocalVlaue(vo.getValue(22), this.pk_localcurr));
                    row.put("creditaccumamount", this.format.getFormatAmountVlaue(vo.getValue(24), vo, pk_currtype_amount));
                    row.put("creditaccumlocamount", this.format.getFormatLocalVlaue(vo.getValue(26), this.pk_localcurr));
                    row.put("endamount", this.format.getFormatAmountVlaue(vo.getValue(65), vo, pk_currtype_amount));
                    row.put("endlocamount", this.format.getFormatLocalVlaue(vo.getValue(67), this.pk_localcurr));
                    row.put("enddebitamount", this.format.getFormatAmountVlaue(vo.getValue(28), vo, pk_currtype_amount));
                    row.put("enddebitlocamount", this.format.getFormatLocalVlaue(vo.getValue(30), this.pk_localcurr));
                    row.put("endcreditamount", this.format.getFormatAmountVlaue(vo.getValue(32), vo, pk_currtype_amount));
                    row.put("endcreditlocamount", this.format.getFormatLocalVlaue(vo.getValue(34), this.pk_localcurr));
                }

                row.put("endorients", vo.getValue(236));
                if (!isExistsMaterial) {
                    row.put("initquant", this.format.getFormatQuan(vo.getValue(60), vo, qryvo.getSubjVersion()));
                    row.put("initdebitquant", this.format.getFormatQuan(vo.getValue(3), vo, qryvo.getSubjVersion()));
                    row.put("initcreditquant", this.format.getFormatQuan(vo.getValue(7), vo, qryvo.getSubjVersion()));
                    row.put("debitquant", this.format.getFormatQuan(vo.getValue(11), vo, qryvo.getSubjVersion()));
                    row.put("creditquant", this.format.getFormatQuan(vo.getValue(15), vo, qryvo.getSubjVersion()));
                    row.put("debitaccumquant", this.format.getFormatQuan(vo.getValue(19), vo, qryvo.getSubjVersion()));
                    row.put("creditaccumquant", this.format.getFormatQuan(vo.getValue(23), vo, qryvo.getSubjVersion()));
                    row.put("endquant", this.format.getFormatQuan(vo.getValue(64), vo, qryvo.getSubjVersion()));
                    row.put("enddebitquant", this.format.getFormatQuan(vo.getValue(27), vo, qryvo.getSubjVersion()));
                    row.put("endcreditquant", this.format.getFormatQuan(vo.getValue(31), vo, qryvo.getSubjVersion()));
                } else {
                    String pk_measdoc = "";
                    if (row.get("mark") == null || !NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0012").equals(row.get("mark").toString())) {
                        String materialPK = this.getMaterialPK(vo);
                        pk_measdoc = (String)materialMeasdocMap.get(materialPK);
                    }

                    row.put("initquant", this.format.getFormatQuanMaterial(vo.getValue(60), pk_measdoc));
                    row.put("initdebitquant", this.format.getFormatQuanMaterial(vo.getValue(3), pk_measdoc));
                    row.put("initcreditquant", this.format.getFormatQuanMaterial(vo.getValue(7), pk_measdoc));
                    row.put("debitquant", this.format.getFormatQuanMaterial(vo.getValue(11), pk_measdoc));
                    row.put("creditquant", this.format.getFormatQuanMaterial(vo.getValue(15), pk_measdoc));
                    row.put("debitaccumquant", this.format.getFormatQuanMaterial(vo.getValue(19), pk_measdoc));
                    row.put("creditaccumquant", this.format.getFormatQuanMaterial(vo.getValue(23), pk_measdoc));
                    row.put("endquant", this.format.getFormatQuanMaterial(vo.getValue(64), pk_measdoc));
                    row.put("enddebitquant", this.format.getFormatQuanMaterial(vo.getValue(27), pk_measdoc));
                    row.put("endcreditquant", this.format.getFormatQuanMaterial(vo.getValue(31), pk_measdoc));
                }

                Object assvosObj = vo.getValue(0);
                if (assvosObj != null && assvosObj.getClass().isArray()) {
                    AssVO[] assvos = (AssVO[])assvosObj;
                    if (mark == null || !NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000115").equals(mark.toString())) {
                        for(int i = 0; i < assvos.length; ++i) {
                            String showassname = "";
                            AssVO assvo = assvos[i];
                            String index = (String)assIndexMap.get(assvo.getPk_Checktype());
                            row.put("checktypecode" + index, assvo.getChecktypecode());
                            row.put("checktypename" + index, assvo.getChecktypename());
                            row.put("checkvaluecode" + index, assvo.getCheckvaluecode());
                            row.put("checkvaluename" + index, assvo.getCheckvaluename());
                            row.put("classid" + index, assvo.getM_classid());
                            row.put("pk_checktype" + index, assvo.getPk_Checktype());
                            row.put("pk_checkvalue" + index, assvo.getPk_Checkvalue());
                            if (qryvo.getFormatVO().isMultiCorpCombine()) {
                                String accountingbook = !StrTools.isEmptyStr(vo.getPk_glorgbook()) ? vo.getPk_glorgbook() : vo.getPk_glorgbook();
                                showassname = ShowContentCenter.getShowAss(accountingbook, new AssVO[]{assvo});
                            } else {
                                showassname = ShowContentCenter.getShowAss(vo.getPk_glorgbook(), new AssVO[]{assvo});
                            }

                            if (showassname.indexOf("【") == 0 && showassname.indexOf("】") == showassname.length() - 1) {
                                showassname = showassname.substring(1, showassname.length() - 1);
                            }

                            row.put("showname" + index, showassname);
                        }
                    }
                }

                data.add(row);
                if (mark != null) {
                    if (mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0012"))) {
                        row.put("linkmsg", NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0013"));
                        continue;
                    }

                    if (qryvo.getpk_accountingbook().length >= 2 && !mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000115"))) {
                        row.put("linkmsg", NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000169"));
                        continue;
                    }

                    if (mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0014")) || !isMultiPages && mark.toString().indexOf(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0015")) >= 0) {
                        continue;
                    }
                }

                Map<String, Object> link = new HashMap();
                if (assvosObj != null && assvosObj.getClass().isArray()) {
                    AssVO[] assvos = (AssVO[])assvosObj;
                    List<Map<String, String>> list = new ArrayList(assvos.length);

                    for(AssVO assvo : assvos) {
                        Map<String, String> map = new HashMap();
                        map.put("pk_checktype", assvo.getPk_Checktype());
                        map.put("pk_checkvalue", assvo.getPk_Checkvalue());
                        list.add(map);
                    }

                    link.put("ass", list);
                }

                link.put("mark", mark);
                link.put("pk_unit", vo.getValue(131));
                link.put("pk_liabilitycenter", vo.getValue(136));
                link.put("year", vo.getValue(43));
                link.put("accsubjcode", vo.getValue(45));
                link.put("pk_accasoa", vo.getValue(42));
                link.put("pk_currtype", vo.getValue(49));
                link.put("pk_accountingbook", vo.getValue(102));
                row.put("link", link);
            }

            return data;
        } else {
            return data;
        }
    }

    private UFDouble multiplyCalculation(Object value, UFDouble fcrate) {
        if (null != value && null != fcrate) {
            UFDouble amount = new UFDouble(value.toString());
            amount = amount.multiply(fcrate);
            return amount;
        } else {
            return null;
        }
    }

    private void processUnitName(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) throws Exception {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (balanceSubjAssVOs != null && balanceSubjAssVOs.length != 0 && qryvo != null && qryvo.getpk_accountingbook().length <= 1) {
            try {
                if (!GLParaAccessor.isSecondBUStart(qryVO.getBaseAccountingbook()).booleanValue()) {
                    return;
                }
            } catch (BusinessException e) {
                Logger.error(e.getMessage(), e);
            }

            HashSet<String> pk_units = new HashSet();

            try {
                for(int i = 0; i < vos.length; ++i) {
                    if (null != vos[i].getValue(131)) {
                        String pk_unit = vos[i].getValue(131).toString();
                        pk_units.add(pk_unit);
                    }
                }
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
            }

            IAccountingbookService service = (IAccountingbookService)NCLocator.getInstance().lookup(IAccountingbookService.class.getName());
            HashMap<String, Object> obj = new HashMap();
            obj.put("pk_unit", pk_units);
            String date = qryvo.getSubjVersion().equals("0000-00-00") ? "0001-01-01" : qryvo.getSubjVersion();
            obj.put("date", qryvo.getDate() == null ? new UFDate(date) : qryvo.getDate());
            HashMap<String, Object> returnObj = service.getObjectOnce(obj);

            for(int i = 0; i < vos.length; ++i) {
                vos[i].setValue(100, (Object)null);
            }

            if (returnObj.containsKey("pk_unit_v")) {
                HashMap<String, String> versionMap = (HashMap)returnObj.get("pk_unit_v");
                HashMap<String, String> unit_name = (HashMap)returnObj.get("unit_name");

                for(int i = 0; i < vos.length; ++i) {
                    if (null != vos[i].getValue(131)) {
                        String pk_unit = vos[i].getValue(131).toString();
                        vos[i].setValue(100, unit_name.get(versionMap.get(pk_unit)));
                    }
                }
            }

        }
    }

    protected void adjustLiabilitycenterVersion(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (balanceSubjAssVOs != null && balanceSubjAssVOs.length != 0 && qryvo != null && qryvo.getpk_accountingbook().length <= 1) {
            try {
                if (!GLParaAccessor.isLbtCenterStart(qryVO.getBaseAccountingbook()).booleanValue()) {
                    return;
                }
            } catch (BusinessException e) {
                Logger.error(e.getMessage(), e);
            }

            try {
                HashSet<String> pk_profits = new HashSet();

                for(int i = 0; i < vos.length; ++i) {
                    if (vos[i].getValue(136) != null && vos[i].getValue(136).equals("00000000emptyposition")) {
                        vos[i].setValue(136, "~");
                    } else {
                        pk_profits.add((String)vos[i].getValue(136));
                    }
                }

                if (pk_profits.size() > 0) {
                    IProfitCenterPubService service = (IProfitCenterPubService)NCLocator.getInstance().lookup(IProfitCenterPubService.class.getName());
                    String date = qryVO.getSubjVersion().equals("0000-00-00") ? "0001-01-01" : qryVO.getSubjVersion();
                    Map<String, ProfitcenterVersionVO> profitVoMap = service.queryVersion((String[])pk_profits.toArray(new String[0]), qryVO.getEndDate() == null ? new UFDate(date) : qryVO.getEndDate());
                    if (profitVoMap.size() > 0) {
                        for(int i = 0; i < vos.length; ++i) {
                            if (null != vos[i].getValue(136)) {
                                ProfitcenterVersionVO profitcenterVersionVO = (ProfitcenterVersionVO)profitVoMap.get(vos[i].getValue(136));
                                if (profitcenterVersionVO != null) {
                                    String lbname = profitcenterVersionVO.getName();
                                    String code = profitcenterVersionVO.getCode();
                                    vos[i].setValue(137, code);
                                    vos[i].setValue(138, lbname);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
            }

        }
    }

    protected void adjustLiabilitycenter(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (balanceSubjAssVOs != null && balanceSubjAssVOs.length != 0 && qryvo != null && qryvo.getpk_accountingbook().length <= 1) {
            try {
                if (!GLParaAccessor.isLbtCenterStart(qryVO.getBaseAccountingbook()).booleanValue()) {
                    return;
                }
            } catch (BusinessException e) {
                Logger.error(e.getMessage(), e);
            }

            try {
                HashSet<String> set = new HashSet();

                for(int i = 0; i < vos.length; ++i) {
                    set.add((String)vos[i].getValue(136));
                }

                set.remove((Object)null);
                set.remove("N/A");
                String[] pk_orgs = (String[])set.toArray(new String[0]);
                IBDData[] datas = GeneralAccessorFactory.getAccessor("310e1300-0681-4062-9ca7-6276d9833901").getDocbyPks(pk_orgs);
                HashMap<String, IBDData> pkliabiliCenterMap = new HashMap();
                Arrays.stream(datas).forEach((datax) -> Optional.ofNullable(datax).ifPresent((x) -> pkliabiliCenterMap.put(x.getPk(), x)));
                if (pk_orgs.length > 0) {
                    for(int i = 0; i < vos.length; ++i) {
                        IBDData data = (IBDData)pkliabiliCenterMap.get(vos[i].getValue(136));
                        vos[i].setValue(137, data == null ? "" : data.getCode().toString());
                        vos[i].setValue(138, data == null ? "" : data.getName().toString());
                    }
                }
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
            }

        }
    }

    private List<IColumnInfo> getColumn(GlQueryVO qryvo) {
        List<IColumnInfo> colList = new ArrayList();
        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000009"), "mark", ColumnInfo.LEFT));
        if (qryvo.isMultiYearList()) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000078"), "year", ColumnInfo.LEFT));
        }

        if (qryvo.getFormatVO().getCorpDispLocation() == 1 && qryvo.getpk_accountingbook().length > 1 && !qryvo.isMultiCorpCombine()) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "1200230400004"), "bookname", ColumnInfo.LEFT));
        }

        if (AccountRepUtil.isBuSupport(qryvo)) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("common", "UCMD1-000396"), "unitname", ColumnInfo.LEFT));
        }

        if (AccountRepUtil.isliabilitycenterSupport(qryvo)) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("common", "UCMD1-000445"), "liabilitycentername", ColumnInfo.LEFT));
        }

        if (!GlQueryVOAssTool.isMultiPages(qryvo)) {
            GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();

            for(int i = 0; i < queryObjs.length; ++i) {
                GLQueryObj queryObj = queryObjs[i];
                if (queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031"))) {
                    colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000010"), "accsubjcode", ColumnInfo.LEFT));
                    colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000011"), "accsubjname", ColumnInfo.LEFT));
                } else {
                    AssVO[] assvos = queryObj.getValueRange();
                    if (assvos != null && assvos[0] != null) {
                        AssVO assvo = assvos[0];
                        colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000033"), "checkvaluecode" + i, ColumnInfo.LEFT));
                        colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000034"), "showname" + i, ColumnInfo.LEFT));
                    }
                }
            }
        } else {
            GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();

            for(int i = 0; i < queryObjs.length; ++i) {
                GLQueryObj queryObj = queryObjs[i];
                if (!queryObj.getHeadEle()) {
                    if (queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031"))) {
                        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000010"), "accsubjcode", ColumnInfo.LEFT));
                        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000011"), "accsubjname", ColumnInfo.LEFT));
                    } else {
                        AssVO[] assvos = queryObj.getValueRange();
                        if (assvos != null && assvos[0] != null) {
                            AssVO assvo = assvos[0];
                            colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000033"), "checkvaluecode" + i, ColumnInfo.LEFT));
                            colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000034"), "showname" + i, ColumnInfo.LEFT));
                        }
                    }
                }
            }
        }

        if (qryvo.getFormatVO().getCorpDispLocation() == 0 && qryvo.getpk_accountingbook().length > 1 && !qryvo.isMultiCorpCombine()) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "1200230400004"), "bookname", ColumnInfo.LEFT));
        }

        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000532"), "measureunit", ColumnInfo.LEFT));
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000012"), "curtype", ColumnInfo.LEFT));
        }

        String[] childStr = null;
        String[] childAlign = null;
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childStr = new String[]{NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000050"), NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000053")};
            childAlign = new String[]{ColumnInfo.RIGTH, ColumnInfo.RIGTH};
        } else {
            childStr = new String[]{NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000050"), NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000051"), NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000053")};
            childAlign = new String[]{ColumnInfo.RIGTH, ColumnInfo.RIGTH, ColumnInfo.RIGTH};
        }

        String[] childKey = null;
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"initquant", "initlocamount"};
        } else {
            childKey = new String[]{"initquant", "initamount", "initlocamount"};
        }

        if (!qryvo.getFormatVO().isTwoWayBalance()) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000134"), "initorients", ColumnInfo.CENTER));
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000459"), childStr, childKey, childAlign));
        } else {
            if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
                childKey = new String[]{"initdebitquant", "initdebitlocamount"};
            } else {
                childKey = new String[]{"initdebitquant", "initdebitamount", "initdebitlocamount"};
            }

            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000479"), childStr, childKey, childAlign));
            if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
                childKey = new String[]{"initcreditquant", "initcreditlocamount"};
            } else {
                childKey = new String[]{"initcreditquant", "initcreditamount", "initcreditlocamount"};
            }

            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000480"), childStr, childKey, childAlign));
        }

        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"debitquant", "debitlocamount"};
        } else {
            childKey = new String[]{"debitquant", "debitamount", "debitlocamount"};
        }

        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000044"), childStr, childKey, childAlign));
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"creditquant", "creditlocamount"};
        } else {
            childKey = new String[]{"creditquant", "creditamount", "creditlocamount"};
        }

        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000045"), childStr, childKey, childAlign));
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"debitaccumquant", "debitaccumlocamount"};
        } else {
            childKey = new String[]{"debitaccumquant", "debitaccumamount", "debitaccumlocamount"};
        }

        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000046"), childStr, childKey, childAlign));
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"creditaccumquant", "creditaccumlocamount"};
        } else {
            childKey = new String[]{"creditaccumquant", "creditaccumamount", "creditaccumlocamount"};
        }

        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000047"), childStr, childKey, childAlign));
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
            childKey = new String[]{"endquant", "endlocamount"};
        } else {
            childKey = new String[]{"endquant", "endamount", "endlocamount"};
        }

        if (!qryvo.getFormatVO().isTwoWayBalance()) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000134"), "endorients", ColumnInfo.CENTER));
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000048"), childStr, childKey, childAlign));
        } else {
            if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
                childKey = new String[]{"enddebitquant", "enddebitlocamount"};
            } else {
                childKey = new String[]{"enddebitquant", "enddebitamount", "enddebitlocamount"};
            }

            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000481"), childStr, childKey, childAlign));
            if (qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())) {
                childKey = new String[]{"endcreditquant", "endcreditlocamount"};
            } else {
                childKey = new String[]{"endcreditquant", "endcreditamount", "endcreditlocamount"};
            }

            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000482"), childStr, childKey, childAlign));
        }

        return colList;
    }

    public void checkQryObjs(GlQueryVO qryVO) throws BusinessException {
        if (qryVO.getDate() == null) {
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000185"));
        } else {
            GlQryFormatVO qryFormatVo = qryVO.getFormatVO();
            int iKmAmount = 0;

            for(GLQueryObj qryObj : qryFormatVo.getQryObjs()) {
                if (!StrTools.isEmptyStr(qryObj.getType())) {
                    if (qryObj.getType().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031"))) {
                        ++iKmAmount;
                    } else if (qryObj.getValueRange()[0] != null && qryObj.getValueRange()[0].getCheckvaluename().equals("ALL") && qryObj.getIncludeSub()) {
                        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000187"));
                    }
                }
            }

            if (iKmAmount == 0) {
                throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000188"));
            } else if (iKmAmount > 1) {
                throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000189"));
            } else {
                GLQueryObj[] aQryObjs = qryFormatVo.getQryObjs();
                boolean blnIsChild = false;
                boolean blnAssIsChild = false;
                String sCorpTmp = AccountBookUtil.getPk_orgByAccountBookPk(qryVO.getBaseAccountingbook());
                if (qryVO.getpk_accountingbook().length == 1 && GLParaAccessor.isSecondBUStart(qryVO.getBaseAccountingbook()).booleanValue() && qryVO.getPk_unis() != null) {
                    sCorpTmp = qryVO.getPk_unis()[0];
                }

                boolean blnSubjAccIsInBody = false;
                boolean blnAssIsInBody = false;
                int iBodyItemCount = 0;

                for(int i = 0; i < aQryObjs.length; ++i) {
                    if ((!blnIsChild || !blnAssIsChild) && !aQryObjs[i].getHeadEle()) {
                        if (aQryObjs[i].getType().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031"))) {
                            if (!aQryObjs[i].getHeadEle()) {
                                blnSubjAccIsInBody = true;
                                ++iBodyItemCount;
                            }

                            if (aQryObjs[i].getValueRange() != null && aQryObjs[i].getValueRange()[0].getCheckvaluecode().contains(",")) {
                                String[] acccode = aQryObjs[i].getValueRange()[0].getCheckvaluecode().split(",");

                                for(int j = 0; j < acccode.length; ++j) {
                                    for(int k = 0; k < acccode.length; ++k) {
                                        if (j != k && acccode[j].startsWith(acccode[k])) {
                                            blnIsChild = true;
                                            break;
                                        }
                                    }
                                }
                            } else {
                                for(int j = 0; j < aQryObjs[i].getValueRange().length; ++j) {
                                    for(int k = 0; k < aQryObjs[i].getValueRange().length; ++k) {
                                        if (j != k && aQryObjs[i].getValueRange()[j].getCheckvaluecode().startsWith(aQryObjs[i].getValueRange()[k].getCheckvaluecode())) {
                                            blnIsChild = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        } else {
                            if (!aQryObjs[i].getHeadEle()) {
                                ++iBodyItemCount;
                                blnAssIsInBody = true;
                            }

                            for(int j = 0; aQryObjs[i].getValueRange() != null && j < aQryObjs[i].getValueRange().length; ++j) {
                                if (aQryObjs[i].getIncludeSub()) {
                                    try {
                                        AssVO[] assVos = CBalanceAssTool.getSubDocsTackle(aQryObjs[i].getValueRange()[j], sCorpTmp);

                                        for(int f = 0; f < assVos.length; ++f) {
                                            for(int k = 0; k < aQryObjs[i].getValueRange().length; ++k) {
                                                if (assVos[f].getPk_Checkvalue().equals(aQryObjs[i].getValueRange()[k].getPk_Checkvalue())) {
                                                    blnAssIsChild = true;
                                                    break;
                                                }
                                            }
                                        }
                                    } catch (Exception e) {
                                        throw new BusinessException(e.getMessage(), e);
                                    }
                                }
                            }
                        }
                    }
                }

                String tempyear = null;
                String tempendyear = null;
                if (qryVO.isQueryByPeriod()) {
                    tempyear = qryVO.getYear();
                    tempendyear = qryVO.getEndYear();
                } else {
                    UFDate date1 = qryVO.getDate();
                    UFDate date2 = qryVO.getEndDate();
                    GlPeriodVO period1 = null;
                    GlPeriodVO period2 = null;

                    try {
                        IGlPeriod itf = (IGlPeriod)NCLocator.getInstance().lookup(IGlPeriod.class.getName());
                        period1 = itf.getPeriod(qryVO.getBaseAccountingbook(), date1);
                        period2 = itf.getPeriod(qryVO.getBaseAccountingbook(), date2);
                    } catch (Exception e) {
                        Logger.error(e.getMessage(), e);
                    }

                    tempyear = period1.getYear();
                    tempendyear = period2.getYear();
                }

                if (blnIsChild && (!blnSubjAccIsInBody || iBodyItemCount != 1)) {
                    qryFormatVo.setAssBalIncludeChildSubj(true);
                    blnIsChild = false;
                }

                if (blnIsChild) {
                    if (!blnSubjAccIsInBody || iBodyItemCount != 1 || qryFormatVo.getCorpDispLocation() == 0 && qryVO.getpk_accountingbook().length > 1 || !tempyear.equals(tempendyear)) {
                        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000190"));
                    }

                    qryFormatVo.setIsSubjAccIncldFatherSon(true);
                } else {
                    qryFormatVo.setIsSubjAccIncldFatherSon(false);
                }

                if (blnAssIsChild) {
                    if (!blnAssIsInBody || iBodyItemCount != 1 || qryFormatVo.getCorpDispLocation() == 0 && qryVO.getpk_accountingbook().length > 1 || !qryVO.getYear().equals(qryVO.getEndYear())) {
                        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000191"));
                    }

                    qryFormatVo.setIsAssIncldFatherSon(true);
                }

                boolean blnHaveTableBodyItem = false;

                for(int i = 0; i < 10; ++i) {
                    for(GLQueryObj obj : aQryObjs) {
                        if (!obj.getHeadEle()) {
                            blnHaveTableBodyItem = true;
                            break;
                        }
                    }
                }

                if (!blnHaveTableBodyItem && aQryObjs.length >= 2) {
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000193"));
                } else if (aQryObjs.length < 2) {
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000194"));
                } else {
                    UFDouble from = qryVO.getFormatVO().getBalanceRangeFrom();
                    UFDouble to = qryVO.getFormatVO().getBalanceRangeTo();
                    if (from == null) {
                        from = UFDouble.ZERO_DBL;
                    }

                    if (to == null) {
                        to = UFDouble.ZERO_DBL;
                    }

                    if (from.compareTo(to) > 0) {
                        throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000195"));
                    }
                }
            }
        }
    }

    private boolean isExistsMaterial(GlQueryVO qryVO) {
        for(GLQueryObj qryObj : qryVO.getFormatVO().getQryObjs()) {
            if (qryObj.getValueRange() != null && qryObj.getValueRange().length > 0 && "eae040f4-3c88-413d-abc9-b15774463d46".equals(qryObj.getValueRange()[0].getM_classid())) {
                return true;
            }
        }

        return false;
    }

    private Map<String, String> getMaterialMeasdoc(BalanceSubjAssBSVO[] vos) throws Exception {
        Map<String, String> map = new HashMap();
        Set<String> pk_material = new HashSet();

        for(BalanceSubjAssBSVO vo : vos) {
            String materialPK = this.getMaterialPK(vo);
            if (!StrTools.isEmptyStr(materialPK) && !"~".equals(materialPK)) {
                pk_material.add(materialPK);
            }
        }

        if (pk_material.size() > 0) {
            MaterialVO[] materialVOs = (MaterialVO[])BDCacheQueryUtil.queryVOsByIDs(MaterialVO.class, "pk_material", (String[])pk_material.toArray(new String[pk_material.size()]), new String[]{"pk_measdoc"});
            if (materialVOs != null && materialVOs.length > 0) {
                for(MaterialVO materialVO : materialVOs) {
                    if (materialVO != null) {
                        map.put(materialVO.getPk_material(), materialVO.getPk_measdoc());
                    }
                }
            }
        }

        return map;
    }

    private String getMaterialPK(BalanceSubjAssBSVO vo) throws Exception {
        AssVO[] assvos = (AssVO[])vo.getValue(0);
        if (assvos != null) {
            for(AssVO assvo : assvos) {
                if ("eae040f4-3c88-413d-abc9-b15774463d46".equals(assvo.getM_classid())) {
                    return assvo.getPk_Checkvalue();
                }
            }
        }

        return null;
    }

    private void setPk_localcurr(String pk_localcurr) {
        this.pk_localcurr = pk_localcurr;
    }
}
